//
//  WHCompanyInfoApplyCell.m
//  WHEasyBizLink
//
//  Created by shengmeng chen on 2024/11/23.

#import "WHCompanyInfoApplyCell.h"
#import "WHCompanyInfoApplyModel.h"
#import "SDAutoLayout.h"

@interface WHCompanyInfoApplyCell ()<UITextFieldDelegate>

@property (nonatomic, weak)UITapGestureRecognizer *textTap;


@end

@implementation WHCompanyInfoApplyCell

-(void)createUIControls
{
    [super createUIControls];
    
    self.backgroundColor =[UIColor redColor];
    /**  *  **/
    UILabel*xingLabel = [[UILabel alloc]init];
    xingLabel.font = [UIFont systemFontOfSize:17*WidthScale>19?19:17*WidthScale];
    xingLabel.textColor =[UIColor redColor];
    [self.contentView addSubview:xingLabel];
    xingLabel.numberOfLines =0;
    xingLabel.text = @"*";
    _xingLabel = xingLabel;
    
    /**  标题,标题  **/
    UILabel*titleLabel = [[UILabel alloc]init];
    titleLabel.font = [UIFont systemFontOfSize:17*WidthScale>19?19:17*WidthScale];
    titleLabel.textColor =[UIColor blackColor];
    [self.contentView addSubview:titleLabel];
    titleLabel.numberOfLines =0;
    titleLabel.text = @"标题,标题,标题,标题,标题,标题";
    _titleLabel = titleLabel;
    
    /**  副标题    **/
    UITextField*textField = [[UITextField alloc]init];
    textField.font = [UIFont systemFontOfSize:16];
    textField.textColor =[UIColor blackColor];
    [self.contentView addSubview:textField];
    textField.delegate = self;
    _textField = textField;
    textField.placeholder = @"例如:********************";
    textField.backgroundColor =[UIColor whiteColor];
   //textField.borderStyle = UITextBorderStyleRoundedRect;
    
    UITapGestureRecognizer *textTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(textAction)];
    self.textField.userInteractionEnabled = YES;
    [self.textField addGestureRecognizer:textTap];
    _textTap = textTap;

}

-(void)setUpUIControlsLayout
{
    [super setUpUIControlsLayout];
    
    /**   标题,标题  **/
    _xingLabel.sd_layout.
    topSpaceToView(self.contentView,kMarginH)
    .leftSpaceToView(self.contentView,kMarginW)
    .widthIs(kMarginW)
    .autoHeightRatio(0);
    
    /**   标题,标题  **/
    _titleLabel.sd_layout.
    topSpaceToView(self.contentView,kMarginH)
    .leftSpaceToView(self.contentView,kMarginW*2)
    .rightSpaceToView(self.contentView,kMarginW*2)
    .autoHeightRatio(0);
    
    _textField.sd_layout.
    topSpaceToView(self.titleLabel,10)
    .leftSpaceToView(self.contentView,kMarginW*2)
    .rightSpaceToView(self.contentView,kMarginW*2)
    .heightIs(40);
    
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField.text.length>0) {
        self.model.contents = textField.text;
    }
}

-(void)textAction
{
    // 在这里处理点击事件
    DebugLog(@"TextField clicked!");
    if(self.clickBtnBlock)
    {
        self.clickBtnBlock(self.model,(int)self.tag);
    }
}
-(void)setModel:(WHCompanyInfoApplyModel *)model
{
    _model = model;
    self.titleLabel.text      = model.titleName;
    self.textField.placeholder= model.holderName;
    self.xingLabel.hidden     = !model.isMust;
    self.textField.text       =  model.contents.length>0?model.contents:@"";
    
    if ([_model.titleName isEqualToString:kComType]||[_model.titleName isEqualToString:kBanknm]||[_model.titleName isEqualToString:kComRegion]) {
        
        self.textTap.enabled = YES;
    }else
    {
        self.textTap.enabled = NO;
        //[self.textField removeGestureRecognizer:self.textTap];
    }
    if ([self.model.titleName isEqualToString:kComTel]) {
        
        self.textField.keyboardType = UIKeyboardTypePhonePad;
    }else if ([self.model.titleName isEqualToString:kaccountno])
    {
        self.textField.keyboardType = UIKeyboardTypeNumberPad;
    }
    else
    {
        self.textField.keyboardType = UIKeyboardTypeDefault;
    }
}

@end
